package com.mazaiting.manager.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mazaiting.common.core.domain.result.ResultCode;
import com.mazaiting.common.core.ex.exceptions.EmptyObjectException;
import com.mazaiting.manager.convert.IOAuthConverter;
import com.mazaiting.manager.domain.entity.SysOauthClient;
import com.mazaiting.manager.dto.SysOauthClientDTO;
import com.mazaiting.manager.mapper.ISysOauthClientMapper;
import com.mazaiting.manager.service.ISysOauthClientService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.Objects;

/**
 * <p>
 * 客户端详情表 服务实现类
 * </p>
 *
 * @author mazaiting
 * @since 2022-08-18
 */
@Slf4j
@Service
@RequiredArgsConstructor
public class SysOauthClientServiceImpl extends ServiceImpl<ISysOauthClientMapper, SysOauthClient> implements ISysOauthClientService {

    private final IOAuthConverter oauthConverter;

    @Override
    public SysOauthClientDTO getOauth2ClientById(String clientId) throws EmptyObjectException {
        // 获取客户端认证信息
        SysOauthClient sysOauthClient = baseMapper.selectById(clientId);
        if (Objects.isNull(sysOauthClient)) {
            throw new EmptyObjectException(ResultCode.OAUTH_CLIENT_NOT_EXIST);
        }
        // entity -> dto
        return oauthConverter.entity2OAuth2Client(sysOauthClient);
    }
}
